from django.db import models
from DjangoUeditor.models import UEditorField


# 用户表
class UserModel(models.Model):
    GENDER_CHOICES_ROLE = (
        (u'1', u'学生'),
        (u'2', u'老师'),
        (u'3', u'管理员'),
    )
    id = models.AutoField(primary_key=True)
    number = models.CharField(max_length=32, verbose_name="学号")
    name = models.CharField(max_length=12, blank=False, null=True, verbose_name="用户名")
    password = models.CharField(max_length=32, blank=False, default='123456', verbose_name="密码")
    phone = models.CharField(max_length=11, blank=False, unique=True, verbose_name="手机号")
    college = models.CharField(max_length=12, null=True, verbose_name="学院")
    college_number = models.CharField(max_length=16, null=True, verbose_name="学院编号")
    professional = models.CharField(max_length=12, null=True, verbose_name="专业")
    professional_number = models.CharField(max_length=16, null=True, verbose_name="专业编号")
    grade = models.CharField(max_length=12, null=True, verbose_name="年级")
    grade_number = models.CharField(max_length=16, null=True, verbose_name="年级编号")
    class_id = models.CharField(max_length=12, null=True, verbose_name="班级")
    class_number = models.CharField(max_length=16, null=True, verbose_name="班级编号")
    role = models.CharField(max_length=2, choices=GENDER_CHOICES_ROLE, default='1')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'users'
        verbose_name = '用户表'
        verbose_name_plural = verbose_name

#教师表
class TeacherModel(models.Model):
    GENDER_CHOICES_ROLE = (
        (u'1', u'学生'),
        (u'2', u'老师'),
        (u'3', u'管理员'),
    )
    id = models.AutoField(primary_key=True)
    number = models.CharField(max_length=16, verbose_name="编号")
    name = models.CharField(max_length=12, blank=False, null=True, verbose_name="用户名")
    password = models.CharField(max_length=32, blank=False, default='123456', verbose_name="密码")
    phone = models.CharField(max_length=11, blank=False, unique=True, verbose_name="手机号")
    role = models.CharField(max_length=2, choices=GENDER_CHOICES_ROLE, default='2')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'teacher'
        verbose_name = '教师表'
        verbose_name_plural = verbose_name

# 学院表
class CollegeModel(models.Model):
    id = models.AutoField(primary_key=True)
    college = models.CharField(max_length=12, blank=False, verbose_name="学院")
    number = models.CharField(max_length=16, blank=False, verbose_name="学院编号")

    def __str__(self):
        return self.college

    class Meta:
        db_table = 'college'
        verbose_name = '学院表'
        verbose_name_plural = verbose_name

#
# 专业表
class ProfessionalModel(models.Model):
    id = models.AutoField(primary_key=True)
    professional = models.CharField(max_length=12, blank=False, verbose_name="专业")
    number = models.CharField(max_length=16, blank=False, verbose_name="专业编号")
    college = models.ForeignKey("CollegeModel", on_delete=models.CASCADE, verbose_name="学院名称")

    def __str__(self):
        return self.professional

    class Meta:
        db_table = 'professional'
        verbose_name = '专业表'
        verbose_name_plural = verbose_name


# 年级表
class GradeModel(models.Model):
    id = models.AutoField(primary_key=True)
    grade = models.CharField(max_length=12, blank=False, verbose_name="年级")
    number = models.CharField(max_length=16, blank=False, verbose_name="年级编号")
    professional = models.ForeignKey("ProfessionalModel", on_delete=models.CASCADE, verbose_name="专业名称")

    def __str__(self):
        return self.grade

    class Meta:
        db_table = 'grade'
        verbose_name = '年级表'
        verbose_name_plural = verbose_name

#
# 班级表
class ClassModel(models.Model):
    id = models.AutoField(primary_key=True)
    class_id = models.CharField(max_length=12, blank=False, verbose_name="班级")
    number = models.CharField(max_length=16, blank=False, verbose_name="班级编号")
    # student = models.ForeignKey("UserModel", on_delete=models.CASCADE, verbose_name="学生")
    grade = models.ForeignKey("GradeModel", on_delete=models.CASCADE, verbose_name="年级")

    def __str__(self):
        return self.class_id

    class Meta:
        db_table = 'class_table'
        verbose_name = '班级表'
        verbose_name_plural = verbose_name

#
# 课程表
class CourseModel(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32, verbose_name="课程名称")
    number = models.CharField(max_length=32, verbose_name="课程编号")
    teacher = models.ForeignKey("TeacherModel", on_delete=models.CASCADE, verbose_name="教师")
    class_table = models.ForeignKey("ClassModel", on_delete=models.CASCADE, verbose_name="班级")

    def __str__(self):
        return self.name

    class Meta:
        db_table = "course"
        verbose_name = "课程表"
        verbose_name_plural = verbose_name
#
#
# 章节表
class ChapterModel(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32, verbose_name="章节名称")
    content = UEditorField(verbose_name="章节内容")
    number = models.CharField(max_length=16, verbose_name="章节编号")
    course = models.ForeignKey("CourseModel", on_delete=models.CASCADE, verbose_name="课程名称")

    def __str__(self):
        return self.name

    class Meta:
        db_table = "chapter"
        verbose_name = "章节表"
        verbose_name_plural = verbose_name



class ExamTaoModel(models.Model):
    id = models.AutoField(primary_key=True)
    tao_name = models.CharField(max_length=64, verbose_name="套题名称")
    course = models.ForeignKey("CourseModel", on_delete=models.CASCADE, verbose_name="课程id")

    def __str__(self):
        return self.tao_name

    class Meta:
        db_table = 'exam_tao'
        verbose_name = '套题表'
        verbose_name_plural = verbose_name


# 单项选择
class ChooseModel(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=64, verbose_name="题目")
    options_a = models.CharField(max_length=128, verbose_name="A")
    options_b = models.CharField(max_length=128, verbose_name="B")
    options_c = models.CharField(max_length=128, verbose_name="C")
    options_d = models.CharField(max_length=128, verbose_name="D")
    answer = models.CharField(max_length=128, verbose_name="答案")
    exam = models.ForeignKey("ExamTaoModel", on_delete=models.CASCADE, verbose_name="套题")
    course = models.ForeignKey("CourseModel", on_delete=models.CASCADE, verbose_name="课程id")

    class Meta:
        db_table = 'exam_choose'
        verbose_name = '单选表'
        verbose_name_plural = verbose_name


# # 多项选择
# class MoreChooseModel(models.Model):
#     id = models.AutoField(primary_key=True)
#     more_title = models.CharField(max_length=64, verbose_name="题目")
#     more_options_A = models.CharField(max_length=128, verbose_name="A")
#     more_options_B = models.CharField(max_length=128, verbose_name="B")
#     more_options_C = models.CharField(max_length=128, verbose_name="C")
#     more_options_D = models.CharField(max_length=128, verbose_name="D")
#     more_answer = models.CharField(max_length=128, verbose_name="答案")
#     exam = models.ForeignKey("ExamTaoModel", on_delete=models.CASCADE, verbose_name="套题")
#     course = models.ForeignKey("CourseModel", on_delete=models.CASCADE, verbose_name="课程id")
#
#     class Meta:
#         db_table = 'exam_more'
#         verbose_name = '多选表'
#         verbose_name_plural = verbose_name


# 判断judge
class JudgeModel(models.Model):
    id = models.AutoField(primary_key=True)
    judge_title = models.CharField(max_length=64, verbose_name="题目")
    judge_options_Y = models.CharField(max_length=128, verbose_name="yes")
    judge_options_N = models.CharField(max_length=128, verbose_name="no")
    judge_answer = models.CharField(max_length=128, verbose_name="答案")
    exam = models.ForeignKey("ExamTaoModel", on_delete=models.CASCADE, verbose_name="套题")
    course = models.ForeignKey("CourseModel", on_delete=models.CASCADE, verbose_name="课程id")

    class Meta:
        db_table = 'exam_judge'
        verbose_name = '判断表'
        verbose_name_plural = verbose_name


# 阅读理解
class ReadingModel(models.Model):
    id = models.AutoField(primary_key=True)
    reading_title = models.CharField(max_length=64, verbose_name="题目")
    reading_answer = models.CharField(max_length=128, verbose_name="答案")
    exam = models.ForeignKey("ExamTaoModel", on_delete=models.CASCADE, verbose_name="套题")
    course = models.ForeignKey("CourseModel", on_delete=models.CASCADE, verbose_name="课程id")

    class Meta:
        db_table = 'exam_read'
        verbose_name = '阅读表'
        verbose_name_plural = verbose_name


# 成绩表
class StudentResultsModel(models.Model):
    id = models.AutoField(primary_key=True)
    student = models.ForeignKey("UserModel", on_delete=models.CASCADE, verbose_name="学生ID")
    exam = models.ForeignKey("ExamTaoModel", on_delete=models.CASCADE, verbose_name="套题")
    course = models.ForeignKey("CourseModel", on_delete=models.CASCADE, verbose_name="课程id")
    choose = models.CharField(max_length=64, verbose_name="单选")
    # more_choose = models.CharField(max_length=64, verbose_name="多选")
    judge = models.CharField(max_length=64, verbose_name="判断")
    read = models.CharField(max_length=64, verbose_name="问答")
    combined = models.CharField(max_length=64, verbose_name="合计")
    data_time = models.CharField(max_length=64, verbose_name="时间")

    class Meta:
        db_table = 'results'
        verbose_name = '成绩表'
        verbose_name_plural = verbose_name
